package com.example.demo02.controller;

import com.example.demo02.common.ResponseEntity;
import com.example.demo02.dto.ShopCouponRespInfo;
import com.example.demo02.exception.TestException;
import com.example.demo02.form.ShopCouponForm;
import com.example.demo02.service.ShopCouponService;
import com.example.demo02.vo.input.ShopCouponSendVo;
import com.example.demo02.vo.result.ShopCouponResultVo;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/shopCoupon")
public class ShopCouponController {
    @Resource
    ShopCouponService shopCouponService;

    @PostMapping("/getShopCouponListByPage")
    public ResponseEntity<Object> getShopCouponListByPage(@RequestBody ShopCouponForm shopCouponForm) {
        try {
            //这是master新增的东西哟
            //新鲜提交
            //dev 合并到  master
            PageInfo<ShopCouponRespInfo> pageInfo = shopCouponService.getShopCouponListByPage(shopCouponForm);
            //master 2
            //master 2
            //dev 2
            //master 2
            return ResponseEntity.success(pageInfo);
        } catch (TestException e) {
            return ResponseEntity.error(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.error("系统内部异常");
        }
    }

    @PostMapping("/getPurchaseListByPage")
    public ResponseEntity<Object> getPurchaseListByPage(@RequestBody ShopCouponSendVo shopCouponSendVo) {
        try {
            PageInfo<ShopCouponResultVo> pageInfo = shopCouponService.getPurchaseListByPage(shopCouponSendVo);
            return ResponseEntity.success(pageInfo);
        } catch (TestException e) {
            return ResponseEntity.error(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.error("系统内部异常");
        }
    }
}
